package org.biodas.jdas.client.adapters.sequence;

import org.biodas.jdas.schema.sequence.DASSEQUENCE;
import org.biodas.jdas.schema.sequence.ERRORSEGMENT;
import org.biodas.jdas.schema.sequence.SEQUENCE;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: ljgarcia
 * Date: 07-Apr-2011
 * Time: 11:48:12
 * To change this template use File | Settings | File Templates.
 */
public class DasSequenceAdapter  extends DASSEQUENCE {
    //Attributes
    private List<SEQUENCE> sequences = null;
    private List<ERRORSEGMENT> errors = null;

    /**
     * New DASSequence adapter.
     */
    public DasSequenceAdapter () {
        init();

    }

    /**
     * New DasSequenceAdapter from a DASSEQUENCE.
     * @param dassequence
     */
    public DasSequenceAdapter (DASSEQUENCE dassequence) {
        this.sequenceOrERRORSEGMENT = dassequence.getSEQUENCEOrERRORSEGMENT();
        init();
    }

    /**
     * Initiates sequences and errors lists.
     */
    private void init() {
        this.sequences = new ArrayList<SEQUENCE>();
        this.errors = new ArrayList<ERRORSEGMENT>();
        for (Object obj:this.sequenceOrERRORSEGMENT){
            if (obj instanceof SEQUENCE) {
                sequences.add((SEQUENCE)obj);
            } else if (obj instanceof ERRORSEGMENT) {
                errors.add((ERRORSEGMENT)obj);
            }
        }
        this.sequenceOrERRORSEGMENT = null;
    }

    /**
     * This  method has been deprecated and will return null, instead use getSequences or getErrors.
     * @return
     */
    @Deprecated
    public List<Object> getSEQUENCEOrERRORSEGMENT() {
        if (this.sequenceOrERRORSEGMENT != null) {
            this.sequenceOrERRORSEGMENT = null;
        }
        return this.sequenceOrERRORSEGMENT;
    }

    /**
     * Returns the list of valid sequences.
     * @return
     */
    public List<SEQUENCE> getSequence() {
        return sequences;
    }

    /**
     * Returns the list of error segments
     * @return
     */
    public List<ERRORSEGMENT> getErrorSegment() {
        return errors;
    }
}
